// ignore_for_file: use_build_context_synchronously, non_constant_identifier_names
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/commom/config/config.dart';
import 'package:verse_systems/commom/global/global.dart';
import 'package:verse_systems/res/colors.dart';
import 'package:verse_systems/utils/account_util.dart';
import 'package:verse_systems/utils/image_utils.dart';
import 'package:verse_systems/utils/images_path.dart';
import 'package:verse_systems/widgets/sp_button.dart';

class Alert {
  static showPolicySheet({
    required Function() onPrivacy,
    required Function() onAgreement,
  }) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      barrierColor: Colors.black54,
      builder: (_) {
        return Container(
          decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(15), topRight: Radius.circular(15))),
          height: MediaQuery.of(context).size.height * 0.55,
          child: Column(
            children: [
              Center(
                child: Container(
                    margin: EdgeInsets.symmetric(vertical: 15.w),
                    child: Text(
                      "agreement_and_privacy".tr,
                      style: TextStyle(
                        fontSize: 20.sp,
                        color: Colors.black,
                        fontWeight: FontWeight.w600,
                      ),
                    )),
              ),
              Container(
                  height: MediaQuery.of(context).size.height * 0.35,
                  margin: EdgeInsets.symmetric(horizontal: 20.w),
                  child: SingleChildScrollView(
                    child: Text.rich(TextSpan(children: [
                      TextSpan(
                        text:
                            "${"thank_user".tr}${Config.getConfigPage()}APP,${"read_agreement_and_privacy".tr} ",
                        style: TextStyle(
                            fontSize: 17.sp, color: Colors.black, height: 1.5),
                      ),
                      TextSpan(
                        text: "《${Config.getConfigPage()}${"service_agreement".tr}》",
                        style: TextStyle(
                          color: Colours.title_text_color,
                          fontSize: 17.sp,
                        ),
                        recognizer: TapGestureRecognizer()..onTap = onAgreement,
                      ),
                      TextSpan(
                        text: "与",
                        style: TextStyle(
                          fontSize: 17.sp,
                          color: Colors.black,
                        ),
                      ),
                      TextSpan(
                        text: "《${Config.getConfigPage()}${"privacy_policy".tr}》",
                        style: TextStyle(
                          color: Colours.title_text_color,
                          fontSize: 17.sp,
                        ),
                        recognizer: TapGestureRecognizer()..onTap = onPrivacy,
                      ),
                      TextSpan(
                        text: "${"terms".tr}\n",
                        style: TextStyle(
                            fontSize: 17.sp, color: Colors.black, height: 1.5),
                      ),
                      TextSpan(
                        text: "\n",
                        style: TextStyle(
                            fontSize: 17.sp, color: Colors.black, height: 1.5),
                      ),
                      TextSpan(
                        text: "${"you_agree".tr}\n",
                        style: TextStyle(
                            fontSize: 17.sp, color: Colors.black, height: 1.5),
                      ),
                    ])),
                  )),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 10.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      width: 160.w,
                      child: SPButton(
                        minHeight: 48.w,
                        fontSize: 16.sp,
                        text: "reject".tr,
                        textColor: Colors.black,
                        radius: 10.w,
                        side: const BorderSide(
                          color: Colours.dark_text,
                          width: 1.0,
                        ),
                        onPressed: () {
                          Navigator.of(context).pop();
                        },
                      ),
                    ),
                    SizedBox(
                      width: 160.w,
                      child: SPButton(
                        minHeight: 48.w,
                        fontSize: 16.sp,
                        text: "agree".tr,
                        textColor: Colours.app_main_color,
                        backgroundColor: Colours.app_main_background_color,
                        radius: 10.w,
                        onPressed: () async {
                          await AccountUtil.setAppHasBeenOpened();
                          Navigator.of(context).pop();
                        },
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        );
      },
    );
  }

  static showAlert({
    required String title,
    required String confirm,
    required String cancel,
    String content = "",
    required Function() onPressed,
  }) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    await showDialog<bool>(
      barrierDismissible: false,
      context: context,
      builder: (context) {
        return AlertDialog(
          titlePadding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 10.w),
          contentPadding: EdgeInsets.symmetric(horizontal: 10.w),
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(10.w))),
          title: Center(
            child: Text(
              title,
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 18.sp,
                color: Colors.black,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
          content: Text(
            content,
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 14.sp,
              color: Colors.black,
            ),
          ),
          actionsAlignment: MainAxisAlignment.spaceAround,
          actions: <Widget>[
            SizedBox(
              width: 95.w,
              child: SPButton(
                minHeight: 35.w,
                fontSize: 13.sp,
                text: cancel,
                textColor: Colors.black,
                radius: 17.5.w,
                side: const BorderSide(
                  color: Colours.dark_text,
                  width: 1.0,
                ),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ),
            SizedBox(width: 15.w),
            SizedBox(
              width: 95.w,
              child: SPButton(
                minHeight: 35.w,
                fontSize: 13.sp,
                text: confirm,
                textColor: Colours.app_main_color,
                backgroundColor: Colours.app_main_background_color,
                radius: 17.5.w,
                onPressed: () async {
                  Navigator.of(context).pop();
                  onPressed();
                },
              ),
            ),
          ],
        );
      },
    );
  }

  static showAPPVersionsSheet({
    required Function() onPressed,
    required Function() onCancel,
  }) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    await showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          contentPadding: const EdgeInsets.all(0),
          backgroundColor: Colors.transparent,
          content: SizedBox(
            height: 323.w,
            child: Column(
              children: [
                Container(
                    width: 320.w,
                    height: 157.w,
                    padding: EdgeInsets.fromLTRB(20.w, 45.w, 100.w, 65.w),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: ExactAssetImage(IMagesPath.getAppVersions()),
                          fit: BoxFit.fill),
                    ),
                    child: Text(
                      "version".tr,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        fontSize: 24.sp,
                        color: Colours.app_main_color,
                      ),
                    )),
                Container(
                    width: 320.w,
                    height: 166.w,
                    decoration: BoxDecoration(
                        color: Colours.app_main_color,
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(20.w),
                            bottomRight: Radius.circular(20.w))),
                    child: Column(
                      children: [
                        Container(
                            margin: EdgeInsets.fromLTRB(40.w, 15.w, 40.w, 35.w),
                            child: Text(
                              "version_info".tr,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                fontSize: 15.sp,
                                color: Colours.app_sendcode_color,
                              ),
                            )),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            SizedBox(
                              width: 95.w,
                              child: SPButton(
                                minHeight: 35.w,
                                fontSize: 13.sp,
                                text: "cancel".tr,
                                textColor: Colours.app_main_background_color,
                                radius: 17.5.w,
                                side: const BorderSide(
                                  color: Colours.app_main_background_color,
                                  width: 1.0,
                                ),
                                onPressed: () {
                                  onCancel();
                                  Navigator.of(context).pop();
                                },
                              ),
                            ),
                            SizedBox(width: 15.w),
                            SizedBox(
                              width: 95.w,
                              child: SPButton(
                                minHeight: 35.w,
                                fontSize: 13.sp,
                                text: "upgrade".tr,
                                textColor: Colours.app_main_color,
                                backgroundColor:
                                    Colours.app_main_background_color,
                                radius: 17.5.w,
                                onPressed: () async {
                                  onPressed();
                                  Navigator.of(context).pop();
                                },
                              ),
                            ),
                          ],
                        ),
                      ],
                    )),
              ],
            ),
          ),
        );
      },
    );
  }

  static showlucky({
    required Function() onPressed,
    required String prize_name,
    required String tips,
  }) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    await showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          contentPadding: const EdgeInsets.all(0),
          backgroundColor: Colors.transparent,
          content: Container(
            constraints: BoxConstraints(minHeight: 325.w, maxHeight: 400.w),
            child: Column(
              children: [
                Container(
                    width: 274.w,
                    padding: EdgeInsets.fromLTRB(0, 20.w, 0, 20.w),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: ExactAssetImage(
                              ImageUtils.getImgPath("lucky_lottery")),
                          fit: BoxFit.fill),
                    ),
                    child: Column(
                      children: [
                        Text(
                          "lottery".tr,
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontSize: 26.sp, color: const Color(0xFF630F03)),
                        ),
                        Container(
                            margin: EdgeInsets.fromLTRB(0, 8.w, 0, 5.w),
                            padding: EdgeInsets.symmetric(horizontal: 53.w),
                            child: Row(children: [
                              Image.asset(
                                ImageUtils.getImgPath("lucky_line"),
                                fit: BoxFit.fill,
                                width: 44.w,
                                height: 3.w,
                              ),
                              Text(
                                "congratulate".tr,
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                    fontSize: 12.sp,
                                    color: const Color(0xFF630F03)),
                              ),
                              Image.asset(
                                ImageUtils.getImgPath("lucky_line"),
                                fit: BoxFit.fill,
                                width: 44.w,
                                height: 3.w,
                              )
                            ])),
                        Text(prize_name.toString(),
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              fontSize: 40.sp,
                              color: Colours.app_main_background_color,
                            )),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 50.w),
                          child: Text(tips.toString(),
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                fontSize: 9.sp,
                                color: Colours.app_text_color,
                              )),
                        ),
                        InkWell(
                          onTap: () {
                            onPressed();
                            Navigator.of(context).pop();
                          },
                          child: Container(
                            alignment: Alignment.center,
                            margin: EdgeInsets.only(top: 30.w),
                            width: 217.w,
                            height: 49.w,
                            decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: ExactAssetImage(
                                      ImageUtils.getImgPath("lucky_button")),
                                  fit: BoxFit.fill),
                            ),
                            child: Text("instantly".tr,
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  fontSize: 18.sp,
                                  color: const Color(0xFF630F03),
                                )),
                          ),
                        )
                      ],
                    )),
                InkWell(
                  onTap: Navigator.of(context).pop,
                  child: Container(
                    margin: EdgeInsets.only(top: 25.w),
                    width: 33.w,
                    height: 33.w,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: ExactAssetImage(
                              ImageUtils.getImgPath("lucky_close")),
                          fit: BoxFit.fill),
                    ),
                  ),
                )
              ],
            ),
          ),
        );
      },
    );
  }

  static showChoiceInfoSheet(
      {required String title,
      required String name,
      required String gender,
      required String number,
      String? real_name ,
      String? real_name_number ,
      String? real_name_gender ,
      String alipay_account = "",
      String alipay_code = "",
      required Function() onPressed}) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    await showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          insetPadding: EdgeInsets.all(30.w),
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(8.w))),
          title: Center(
            child: Text(
              title,
              style: TextStyle(
                fontSize: 18.sp,
                color: Colors.black,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
          content:  Container(
            width: MediaQuery.of(context).size.width,
            constraints: BoxConstraints(minHeight: 110.w, maxHeight: 180.w),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "please_entered_no_err".tr,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: Colors.black,
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 17.w, 0, 6.w),
                  child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      real_name??"real_name".tr,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                    Text(
                      name,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                  ],
                ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      real_name_number??"real_name_number".tr,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                    Text(
                      number,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                  ],
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 6.w, 0, 6.w),
                  child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      real_name_gender??"real_name_gender".tr,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                    Text(
                      gender,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                  ],
                ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      alipay_account,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                    Text(
                      alipay_code,
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colours.calendar_open_text_color,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          actionsAlignment: MainAxisAlignment.spaceAround,
          actions: <Widget>[
            SizedBox(
              width: 95.w,
              child: SPButton(
                minHeight: 35.w,
                fontSize: 13.sp,
                text: "cancel".tr,
                textColor: Colours.app_main_color,
                backgroundColor:
                    Colours.stringAnAlphaColor("0xffFC5129", alpha: 0.5),
                radius: 17.5.w,
                onPressed: () async {
                  Navigator.of(context).pop();
              
                },
              ),
            ),
            SizedBox(width: 15.w),
            SizedBox(
              width: 95.w,
              child: SPButton(
                minHeight: 35.w,
                fontSize: 13.sp,
                text: "confirm".tr,
                textColor: Colours.app_main_color,
                backgroundColor: Colours.app_main_background_color,
                radius: 17.5.w,
                onPressed: () async {
                  Navigator.of(context).pop();
                  onPressed();
                },
              ),
            ),
          ],
        );
      },
    );
  }

  static showChoicelogoOffSheet(
      {required Function() onPressed,
      required String hotline,
      required String work_hour}) async {
    BuildContext context = Global.navigatorKey.currentState!.overlay!.context;
    await showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          insetPadding: EdgeInsets.all(30.w),
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(5.w))),
          title: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              InkWell(
                onTap: Navigator.of(context).pop,
                child: Icon(
                  Icons.close_outlined,
                  color: Colors.black,
                  size: 20.w,
                ),
              )
            ],
          ),
          content: SizedBox(
            width: MediaQuery.of(context).size.width,
            height: 200.w,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "contact_service".tr,
                  style: TextStyle(
                    fontSize: 20.sp,
                    color: Colors.black,
                  ),
                ),
                Text(
                  "${"call_service".tr}\n${"service_number".tr}:$hotline",
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: Colours.app_logoff_serve_text_color,
                  ),
                ),
                Text(
                  work_hour.toString(),
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: Colours.calendar_open_text_color,
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(38.w, 30.w, 38.w, 0),
                  width: 230.w,
                  child: SPButton(
                    minHeight: 46.w,
                    fontSize: 18.sp,
                    text: "call_service_number".tr,
                    textColor: Colours.app_main_color,
                    backgroundColor: Colours.app_main_background_color,
                    radius: 23.w,
                    onPressed: () async {
                      Navigator.of(context).pop();
                      onPressed();
                    },
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
